#ifndef TABLE_H
#define TABLE_H

#include <vector>
#include "global.h"
#include "rule.h"

namespace fouine
{

class Rule;

class Table
{
  friend class Grammar;
  public:
    Table(RuleId nb_rules, StrLen str_length, StrLen max_length=15);
    ~Table();
    inline Likelihood& operator()(fouine::StrId start, fouine::StrLen length, fouine::RuleId rule_id);
    inline Likelihood  operator()(fouine::StrId start, fouine::StrLen length, fouine::RuleId rule_id) const;
    inline StrLen maxLength() const;
    inline StrLen strLength() const;
  private:
    Table();
    RuleId _nb_rules;
    StrLen _str_length;
    StrLen _max_length;
  protected:
    Likelihood*** _t; // length, rules, first
};


inline StrLen Table::strLength() const {
  return _str_length;
}

inline StrLen Table::maxLength() const {
  return _max_length;
}
    
inline Likelihood& Table::operator()(StrId a, StrLen l, RuleId r) {
  return _t[l][r][a];
}

inline Likelihood Table::operator()(StrId a, StrLen l, RuleId r) const {
  return _t[l][r][a];
}

}


#endif // TABLE_H
